package com.liuzhilong.infrastructure.basic.factory.statics.inner;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 *     模拟value的创建过程，静态工厂模式
 * </p>
 * <p>
 *
 * </p>
 *
 *
 *
 * @author longandai@163.com
 */
@Getter
@Setter(AccessLevel.PRIVATE)
@Accessors(chain = true)
public class SimpleValue {
    private String name;
    private String attr;
    private Integer count;

    private SimpleValue(){

    }

    /**
     * 从entity中生成value。转化中的特殊逻辑可以放在这里面
     * @param simpleEntity
     * @return
     */
    public static final SimpleValue fromEntity(SimpleEntity simpleEntity){
        return new SimpleValue()
                .setAttr(simpleEntity.getSomeOtherAttr())
                .setCount(simpleEntity.getCount()>100?1000:simpleEntity.getCount())
                .setName(simpleEntity.getName());
    }


    /**
     * 默认值
     * @return
     */
    public static final SimpleValue defaultValue(){
        return new SimpleValue().setName("default").setCount(0).setAttr("defualt");
    }




}
